#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Name:     Chain.py
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Version:  111208

from .. mol import Mol

def chain(n, e = 'C'):
    m = Mol()
    if n <= 0:
        idx0 = m.add_atom('H')
    else:
        idx0 = m.add_atom(e)
    idx1 = idx0
    for i in range(int(n)-1):
        idx1 = m.add_atom(e)
        m.add_bond(idx1, idx0)
        idx0 = idx1
    idx2 = m.add_atom('*')
    if not idx1 is None:
        m.add_bond(idx1, idx2)
    return m.get_mol()
   
if __name__ == '__main__':
    open('12c.mol', 'w').write(chain(12, 'C'))
